<?php

if (!defined('IN_FINECMS')) exit();

/**
 *  custom.php 用户自定义函数/类库
 */
function _formtype()
{
    return array(
        'xiaoqu' => '小区名', //前者test表示字段的英文名称，后者表示字段的描述名称
        'fbianhao' => '房产编号', //前者membergroup表示字段的英文名称，后者表示字段的描述名称
        'yunsuan' => '运算字段', //前者membergroup表示字段的英文名称，后者表示字段的描述名称
    );
}


function form_yunsuan($setting = null)
{
    $default = isset($setting['default']) ? $setting['default'] : ''; //默认值，都能看懂
    //调用会员组表中的数据

    $model = Controller::model('content'); //实例化会员组模型
    $data = $model->from('content_1')->getAll('catid=?','2');   ; //获取会员组表中的全部数据，用于设置默认值
    $select = '<select name="setting[default]"><option value="0"> -- </option>';
    foreach ($data as $t) {
        $selected = $default == $t['id'] ? 'selected' : '';
        $select .= '<option value="' . $t['id'] . '" ' . $selected . '> ' . $t['title'] . ' </option>';
    }
    $select .= '</select>';
    return '
    <table width="98%" cellspacing="1" cellpadding="2">
    <tbody>
    <tr>
    <td width="100">默认小区 ：</td>
    <td>' . $select . '</td>
    </tr>
    </tbody>
    </table>';
}

function content_yunsuan($name, $content = null, $field = null)
{
    $setting = isset($field['setting']) ? string2array($field['setting']) : $field; //配置
    $required = isset($field['not_null']) && $field['not_null'] ? ' required' : ''; //必填字段
//$errortips = isset($field['errortips']) && $field['errortips'] ? ' placeholder="' . $field['errortips'] . '"' : ''; //错误提示
    $pattern = isset($field['pattern']) && $field['pattern'] ? ' pattern="' . $field['pattern'] . '"' : ''; //正则判断
    $content = is_null($content[0]) ? get_content_value($setting['default']) : $content[0]; //字段内容，固定值
    $content= $default="A".date("YmdHis");
    return '<input type="text" value="' . $content . '" class="input-text" name="data[' . $name . ']" width=' . $setting['size'] . '>'; //表单Name值格式为data[字段名称]
}



function form_xiaoqu($setting = null)
{
    $default = isset($setting['default']) ? $setting['default'] : ''; //默认值，都能看懂
    //调用会员组表中的数据

    $model = Controller::model('content'); //实例化会员组模型
    $data = $model->from('content_1')->getAll('catid=?','21');   ; //获取会员组表中的全部数据，用于设置默认值
    $select = '<select name="setting[default]"><option value="0"> -- </option>';
    foreach ($data as $t) {
        $selected = $default == $t['id'] ? 'selected' : '';
        $select .= '<option value="' . $t['id'] . '" ' . $selected . '> ' . $t['title'] . ' </option>';
    }
    $select .= '</select>';
    return '
    <table width="98%" cellspacing="1" cellpadding="2">
    <tbody>
    <tr>
    <td width="100">默认小区 ：</td>
    <td>' . $select . '</td>
    </tr>
    </tbody>
    </table>';
}

function content_xiaoqu($name, $content = null, $field = null)
{
    $setting = isset($field['setting']) ? string2array($field['setting']) : $field; //配置
    $required = isset($field['not_null']) && $field['not_null'] ? ' required' : ''; //必填字段
    $errortips = isset($field['errortips']) && $field['errortips'] ? ' placeholder="' . $field['errortips'] . '"' : ''; //错误提示
    $pattern = isset($field['pattern']) && $field['pattern'] ? ' pattern="' . $field['pattern'] . '"' : ''; //正则判断
    $content = is_null($content[0]) ? get_content_value($setting['default']) : $content[0]; //字段内容，固定值
//调用会员组表中的数据
    $model = Controller::model('content'); //实例化会员组模型
    $data =  $model->from('content_1')->getAll('catid=?','21');   //获取会员组表中的全部数据，用于设置默认值

    $select = '<select name="data[' . $name . ']"><option> -- </option>'; //表单Name值格式为data[字段名称]
    foreach ($data as $t) {
        $selected = $content == $t['id'] ? 'selected' : '';
        $select .= '<option value="' . $t['id'] . '" ' . $selected . '> ' . $t['title'] . ' </option>';
    }
    $select .= '</select>';
    return $select;
}





function form_fbianhao($setting = null)
{
    $size = isset($setting['size']) ? $setting['size'] : 150; //如果不填写长度，默认为150
    $default = isset($setting['default']) ? $setting['default'] : ''; //默认值，都能看懂
    //  $default="A".date("YmdHis");
    return '
<table width="98%" cellspacing="1" cellpadding="2">
<tbody>
<tr>
<td width="100">文本框长度 ：</td>
<td><input type="text" class="input-text" size="10" value="' . $size . '" name="setting[size]"><font color="gray">px</font></td>
</tr>
<tr>
<td>编码前缀 ：</td>
<td><input type="text" class="input-text" size="30" value="' . $default . '" name="setting[default]"></td>
</tr>
</tbody>
</table>';
}


function content_fbianhao($name, $content = null, $field = null)
{
    $setting = isset($field['setting']) ? string2array($field['setting']) : $field; //配置
    $required = isset($field['not_null']) && $field['not_null'] ? ' required' : ''; //必填字段
//$errortips = isset($field['errortips']) && $field['errortips'] ? ' placeholder="' . $field['errortips'] . '"' : ''; //错误提示
    $pattern = isset($field['pattern']) && $field['pattern'] ? ' pattern="' . $field['pattern'] . '"' : ''; //正则判断
    $content = is_null($content[0]) ? get_content_value($setting['default']) : $content[0]; //字段内容，固定值
    $content .=  get_content_value($setting['default']) .date("YmdHis");
    return '<input type="text" value="' . $content . '" class="input-text" name="data[' . $name . ']" width=' . $setting['size'] . '>'; //表单Name值格式为data[字段名称]
}
